<template>
	<view>
		<uni-nav-bar left-icon="left" :statusBar="true"   titleSize="30px" leftText="返回" right-icon="more-filled"  title="选择操作"  @clickLeft="back"  :fixed="true" backgroundColor="#3286ed" color="#fff"/>
	
	   <view class="btn">
	   	<u-button type="success" style="margin: 30px;width: 300px;"  text="激活机器" @click="activateMachine"></u-button>
		<u-button type="primary" style="margin: 30px;width: 300px;"  text="恢复使用" @click="activateMachine2"></u-button>
		<u-button type="warning" style="margin: 30px;width: 300px;"   text="维修机器" @click="toMaintain"></u-button>
		<!-- <u-button type="primary" text=""></u-button> -->
	   </view>
	   <view class="info">
		   <view  style="height:20px;line-height:20px;background-color: #fff;padding-left:10px;fonit-size: 20px;color:#fd9540 ;">
		   	机器信息
		   </view>
	   	<u--form labelPosition="left" labelWidth="90px" class="form" :model="formData"ref="form1">
	   				<u-form-item label="产品名称" prop="productName" borderBottom ref="item1">
	   					<u--input disabled disabledColor="#fff" v-model="formData.productName"border="none"></u--input>
	   				</u-form-item>
					<u-form-item label="产品编号" prop="productNo" borderBottom ref="item1">
						<u--input disabled disabledColor="#fff" v-model="formData.productNo"border="none"></u--input>
					</u-form-item>
					<u-form-item label="型号" prop="model" borderBottom ref="item1">
						<u--input disabled disabledColor="#fff" v-model="formData.model"border="none"></u--input>
					</u-form-item>
					<u-form-item label="机器编号" prop="machineNo" borderBottom ref="item1">
						<u--input disabled disabledColor="#fff" v-model="formData.machineNo"border="none"></u--input>
					</u-form-item>
					<u-form-item label="仓库" prop="warehouseName" borderBottom ref="item1">
						<u--input disabled disabledColor="#fff" v-model="formData.warehouseName"border="none"></u--input>
					</u-form-item>
					<u-form-item label="机器状态" prop="status" borderBottom ref="item1">
						 
								 <u-button type="text" style="color: #fd9540;margin-right: 100px;" size="mini" v-if="formData.status=='0'">正常</u-button>
								 <u-button type="text" style="color: #fd9540;" size="mini" v-if="formData.status=='1'">不可用</u-button>
								 <u-button type="text" style="color: #fd9540;" size="mini" v-if="formData.status=='2'">使用中</u-button>
								 <u-button type="text" style="color: #fd9540;" size="mini" v-if="formData.status=='3'">未激活</u-button>
						 
					</u-form-item>
					<u-form-item label="机器序列号" prop="machineSerialNumber" borderBottom ref="item1">
						<u--input disabled disabledColor="#fff" v-model="formData.machineSerialNumber"border="none"></u--input>
					</u-form-item>
					
	   	</u--form>
		<u-toast ref="uToast"></u-toast>
	   </view>
	</view>
</template>

<script>
	import {machineList,modifyMachineApi} from '@/api/machine/machine.js'
	export default {
		data() {
			return {
				formData:{}
			};
		},
		onLoad(e) {
			console.log(e);
			this.initData(e)
		},
		methods:{
			async initData(e){
				let res=await machineList({machineNo:e.machineSerialNumber})
				this.formData=res.rows[0]
			},
			// 激活机器ss
			async activateMachine(){
				this.formData.status='0'
				await modifyMachineApi(this.formData)
				this.$refs.uToast.show({
					type:'success',
					message:'恭喜你，成功激活机器',
					
				})
			},
			// 回复使用
			async activateMachine2(){
				this.formData.status='2'
				await modifyMachineApi(this.formData)
				this.$refs.uToast.show({
					type:'success',
					message:'机器可以正常使用啦',
					
				})
			},
			// 维修机器
			toMaintain(val){
				uni.navigateTo({
					url:'/pages/repair/addRepair/index?machineNo='+this.formData.machineNo
				})
			},
			back(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style lang="scss">
.btn{
	width: 100%;
}
.form{
	
	background-color: #fff;
	padding-left: 10px;
	padding-right: 10px;
}
</style>
